/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.menosehmais.persistence;

import br.com.caelum.vraptor.ioc.Component;
import br.com.menosehmais.framework.persistence.DaoJpa2;
import br.com.menosehmais.model.PortletClickDO;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

/**
 *
 * @author Junior JAFJ
 */
@Component
public class ClickPortletDAO extends DaoJpa2<PortletClickDO> {
    
    public ClickPortletDAO(EntityManager em) {
        super(PortletClickDO.class, em);
    }
    
    public long countByPortletId(String portletId, String userId) {
        String jpql = "SELECT COUNT(id) FROM PortletClickDO pc WHERE pc.portlet.id = :portletId AND pc.usuario.id = :userId";

        TypedQuery<Long> query = entityManager.createQuery(jpql, Long.class);
        query.setParameter("portletId", portletId);
        query.setParameter("userId", userId);
        long result = query.getSingleResult();

        return result;
    }
    
}
